package com.lp.biz.member.controller;

import com.lp.biz.member.model.query.DistributorQuery;
import com.lp.biz.member.model.vo.RateList;
import com.lp.biz.member.service.WithdrawalService;
import com.lp.common.annotation.PermissionAnnotation;
import com.lp.common.utils.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import static com.lp.common.constant.MenuConstant.WITHDRAWAL;

/**
 * @program: backend
 * @description:
 * @author: Ke.Song
 * @since: 2024-06-29 20:56:52
 */
@RestController
@RequestMapping("/withdrawal")
public class WithdrawalController {

    @Autowired
    private WithdrawalService withdrawalService;

    /**
     * 分销人列表
     * @param query 查询参数
     * @return 查询结果
     */
    @GetMapping("/distributor")
    @PermissionAnnotation(menus = {WITHDRAWAL})
    public CommonResult getDistributorList(DistributorQuery query) {
        return withdrawalService.getDistributorList(query);
    }

    /**
     * 分销人提现记录
     * @param query 查询参数
     * @return 查询结果
     */
    @GetMapping("/histories")
    @PermissionAnnotation(menus = {WITHDRAWAL})
    public CommonResult getHistories(DistributorQuery query) {
        return withdrawalService.getHistories(query);
    }

    /**
     * 分销比例
     * @return 查询结果
     */
    @GetMapping("/rate")
    @PermissionAnnotation(menus = {WITHDRAWAL})
    public CommonResult getRateList() {
        return withdrawalService.getRateList();
    }

    /**
     * 更新分销比例
     * @param rate 分销参数
     * @return 处理结果
     */
    @PutMapping("/rate")
    @PermissionAnnotation(menus = {WITHDRAWAL})
    public CommonResult updateRate(@RequestBody @Validated RateList rate) {
        withdrawalService.updateRate(rate);
        return CommonResult.success();
    }

}
